package cn.chair.dao;

import cn.chair.entity.Merchant;
import cn.chair.model.admin.MerchantListResp;
import cn.chair.model.admin.MerchantResp;
import life.innovation.dao.EntityDaoImpl;
import life.innovation.exception.DataReadException;
import life.innovation.model.PageList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class MerchantDao extends EntityDaoImpl<Merchant> {
    private static final Logger elog = LoggerFactory.getLogger("errorLogger");

    public MerchantDao(DataSource dataSource) {
        super(dataSource, Merchant.class);
    }




   public PageList<MerchantListResp.MerchantList> getMerchantList(Integer regionId, Integer merId,
                                                                  String merName,Integer status,int page, int countPerPage) throws DataReadException {


       Map<String,Object>  params = new HashMap<>();
       params.put("regionId",regionId);
       params.put("merId",merId);
       params.put("status",status);

       if(merName !=null&&!merName.trim().isEmpty()){
           merName = "%"+merName.trim()+"%";
       }else {
           merName = null;
       }

       params.put("merName",merName);

     return findPage("db/sql/merchant/getMerchantsList.sql",MerchantListResp.MerchantList.class,page,countPerPage,params);


   }

    /**
     * 获取影院列表
     * @param storeId
     * @return
     */
   public List<MerchantResp> getList(List<Integer> storeId) throws DataReadException {
        Map<String,Object> params = new HashMap<>();
        params.put("status",Merchant.STATUS_ACTIVE);
        if(storeId!=null &&storeId.size()>0){
            params.put("store",storeId.get(0));
        }else{
            params.put("store",null);
        }
        params.put("storeId",storeId);

        return find("db/sql/merchant/getMerchants.sql",MerchantResp.class,params);


   }

}
